<?php
 /**
 * 功能描述：	通用模块
 * @datetime	2022-09-28
 * @version   	v1.0
 * @author   	ZHL
 * @copyrigh  	2022 ZHL 版权所有
 */

class Admin_CommonController extends Controller {

    function index(){
        exit('common');
    }

    /**
     * Notes:删除
     * User: ZHL
     * Date: 2022/7/18
     */
    public function del(){
        $m = Fun::input('m');
        $id = Fun::input('i', 0, 'd');
        $commS = new Admin_CommonServe();
        $result = $commS->del($m, $id);
        Fun::json($result, true);
    }

    /**
     * Notes:批量删除
     * User: ZHL
     * Date: 2022/7/18
     */
    public function dels(){
        $m = Fun::input('m');
        $idStr = Fun::input('i');
        $commS = new Admin_CommonServe();
        $result = $commS->dels($m, $idStr);
        Fun::json($result, true);
    }

    /**
     * Notes:批量修改状态
     * User: ZhuHaili
     */
    public function status(){
        $m = Fun::input('m');
        $newStatus = Fun::input('s');
        $idStr = Fun::input('i');
        $commS = new Admin_CommonServe();
        $result = $commS->batchUpdateStatus($m, $idStr, $newStatus);
        Fun::json($result, true);
    }

    /**
     * Notes: 批量排序
     * User: ZHL
     * Date: 2022/7/18
     */
    public function seq($m = ''){
        $mould = $m ? $m : Fun::input('m');
        $param = Fun::input('param');
        $commS = new Admin_CommonServe();
        $result = $commS->batchSeq($mould, $param);
        Fun::json($result, true);
    }

    /**
     * Notes:单表公共分页列表
     * User: ZhuHaili
     * Date: 2022/9/28
     * @param $mouldCode
     * @param $temp
     * @param string $title
     * @param string $orderby
     */
    public function lists($mouldCode, $temp, $title = '列表', $orderby = ''){
        // 接收参数
        $pageNo = Fun::input('p', 1, 'd');
        $search = isset($_POST['search']) ? json_decode($_POST['search'], true) : array();
        // 文章列表
        $essaySer = new Admin_CommonServe();
        $result = $essaySer->getListsPage($mouldCode, $pageNo, $search, $orderby);
        if(!is_array($result)){
            htmlAlert($result);
        }
        // 用户权限信息
        $powerSer = new Admin_PowerServe();
        $powerInfo = $powerSer->getUserPowerInfo();
        // 映射
        $this->set('powerInfo', $powerInfo);
        $this->set('statusList', BaseData::$statusArr2);
        $this->set('userLevel', getUserLevel());
        $this->set('searchInfo', $result['where']);
        $this->set('list', $result['list']);
        $this->set('pages', $result['pages']);
        $this->set('title', $title);
        $this->set('mouldCode', $mouldCode);
        $this->display($temp);
    }



}